package de.hsb.ai.devil;

import jade.Boot;
import jade.core.Agent;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.UIManager;

import org.apache.log4j.Logger;

import de.hsb.ai.devil.agent.DevilManagementAgent;
import de.hsb.ai.devil.agent.DevilMasterAgent;
import de.hsb.ai.devil.agent.InteractivePlayerAgent;
import de.hsb.ai.devil.agent.PerfectPlayerAgent;
import de.hsb.ai.devil.agent.RandomPlayerAgent;

public class Main {
	
	private static Logger logger = Logger.getLogger(Main.class);
	
	static {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			logger.error("Setting L&F failed", e);
		}
	}

	/**
	 * Main program.
	 * @param args
	 */
	public static void main(String[] args) {
		Map<String, Class<? extends Agent>> agents = new LinkedHashMap<String, Class<? extends Agent>>(4);
		agents.put("manager", DevilManagementAgent.class);
		agents.put("master", DevilMasterAgent.class);
		agents.put("player1", PerfectPlayerAgent.class);
		agents.put("player2", RandomPlayerAgent.class);
		agents.put("player3", InteractivePlayerAgent.class);
		
		String[] jade_args = {"-gui", "-name Horst", "-services jade.tools.rma.rma,jade.domain.df", stringifyAgents(agents)};
		
		Boot.main(jade_args);
	}

	private static String stringifyAgents(Map<String, Class<? extends Agent>> agents) {
		StringBuilder builder = new StringBuilder();
		for (Entry<String, Class<? extends Agent>> e : agents.entrySet()) {
			builder.append(e.getKey()).append(':').append(e.getValue().getCanonicalName()).append(';');
		}
		logger.info(builder.toString());
		return builder.toString();
	}

}
